package com.fita.admin.entity;

import com.demo2do.core.utils.Alias;
import org.apache.commons.lang3.StringUtils;

/**
 * 
 * @author mohanlan
 *
 */
@Alias("PaymentPayType")
public enum PayType {
    
    PC("pc", "无卡支付"), // 网页支付（银行卡、支付宝扫码、微信扫码）
    
    WECHAT("wechat", "微信支付"), // 微信网页
    
    ALIPAY("alipay", "支付宝生活号"); // 支付宝生活号
    
    private String code;

    private String description;

    /**
     *
     * @param code
     * @param description
     */
    PayType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * get pay channel by the code
     *
     * @param code
     * @return
     */
    public static PayType codeOf(String code) {
        for(PayType channel : PayType.values()) {
            if(StringUtils.equalsIgnoreCase(channel.getCode(), code)) {
                return channel;
            }
        }
        return null;
    }

    /**
     * whether pay channel supports code
     *
     * @param code
     * @return
     */
    public static boolean supports(String code) {
        return codeOf(code) != null;
    }
    
    public boolean isPc() {
        return StringUtils.equalsIgnoreCase(this.getCode(), "pc");
    }

    /**
     *
     * @return
     */
    public boolean isAlipay() {
        return StringUtils.equalsIgnoreCase(this.getCode(), "alipay");
    }

    /**
     *
     * @return
     */
    public boolean isWechat() {
        return StringUtils.equalsIgnoreCase(this.getCode(), "wechat");
    }

    /**
     * @return the code
     */
    public String getCode() {
        return this.code;
    }

    /**
     *
     * @return
     */
    public String getName() {
        return this.name();
    }

    /**
     *
     * @return
     */
    public int getOrdinal() {
        return this.ordinal();
    }

    public String getDescription() {
        return description;
    }

}
